package com.ls.blog.controller;


import com.ls.blog.dto.CategoryDTO;
import com.ls.blog.entity.Category;
import com.ls.blog.service.CategoryService;
import com.ls.blog.utils.ObjectUtils;
import com.ls.blog.utils.R;
import com.ls.blog.utils.Result;
import com.ls.blog.vo.CategoryVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import static com.ls.blog.common.consts.Methods.*;

@RestController
@RequestMapping("/category")
@Api(tags = "分类模块")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @GetMapping("/admin/list")
    @ApiOperation(value = "后台文章分类选项",httpMethod = GET)
    public Result<List<CategoryDTO>> category(){
        return R.ok(categoryService.listCategoryDTO());
    }

    @GetMapping("/admin/getCategoryById/{id}")
    @ApiOperation(value = "后台根据id查找分类信息",httpMethod = GET)
    public Result<CategoryDTO> getCategoryById(@PathVariable("id") Long id){
        return R.ok(categoryService.getCategoryById(id));
    }

    @PutMapping("/admin/update")
    @ApiOperation(value = "后台更新分类信息",httpMethod = PUT)
    public Result<?> updateCategory(@RequestBody CategoryVO categoryVO){
        categoryService.updateCategory(categoryVO);
        return R.ok();
    }

    @PostMapping("/admin/save")
    @ApiOperation(value = "保存分类",httpMethod = POST)
    public Result<?> saveCategory(@RequestBody CategoryVO categoryVO){
        categoryService.saveCategory(categoryVO);
        return R.ok();
    }

    @DeleteMapping("/admin/delete/{id}")
    @ApiOperation(value = "删除分类",httpMethod = DELETE)
    public Result<?> deleteCategory(@PathVariable("id") Long id){
        categoryService.deleteCategory(id);
        return R.ok();
    }





}
